<?php
/**
 * Created by PhpStorm.
 * User: 86188
 * Date: 2021/1/28
 * Time: 14:12
 */

namespace app\admin\command;

use app\service\iotmcuService;
use app\service\wotuService;
use think\console\Command;
use think\console\Input;

use think\console\Output;
use think\Db;

class Updatejkm extends Command
{
    protected function configure()
    {
        $this->setName('updatejkm')->setDescription('Here is update jkm ');
    }

    protected function execute(Input $input, Output $output)
    {
        $userlist=Db::table("personnel")->where("ryid","<>","0")->select();
        foreach ($userlist as $userinfo){

            $res=(new iotmcuService())->getJkmztByRyid($userinfo["xmcode"],$userinfo["ryid"],$userinfo["idcard"],$userinfo["relation"]);
            //$output->writeln($res);
            //return ;
            $re=json_decode($res,true);

            if($re["code"]=="0"){

                Db::table("personnel")->where("id",$userinfo["id"])->update(["mzt"=>$re["data"]["mzt"],"mzt_update_time"=>date('Y-m-d H:i:s')]);
                if($userinfo["personGuid"]!="0"){
                    $woinfo["idcard"]=$userinfo["idcard"];
                    $woinfo["name"]=$userinfo["name"];
                    $woinfo["mzt"]=$re["data"]["mzt"];
                    $p=(new wotuService())->personUpdate($userinfo["personGuid"],$woinfo);
                    //var_dump($p);
                }



            }else{
                $output->writeln("查询失败");

            }
        }
        $output->writeln("OK");
    }
}